package com.tusuo.stds.rest;

import android.text.TextUtils;

import com.tusuo.stds.util.DateUtils;

import org.parceler.Parcel;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author J.Huang
 * @version 1.0
 *
 */
@Parcel
public class LevelDetail extends ApiResult {
    public static final String EXTRA_NAME = LevelDetail.class.getName();

    public int Id;  // 闯关记录Id
    public int LevelId;  // 关卡Id
    public String Title;
    public int QuestionCount;
    public String Description;
    public int LevelType;
    public float CorrectRate;
    public String ThroughTime;
    public int ClearanceTime;
    public int CompletionStatus;
    public int LockStatus;
    public LevelList.Level PreLevel;
    public SceneList.Scene PreScene;
    public List<Question> QuestionList;
    public RankList.Rank BestRank;
    public int CompleteType;


    public String getFormattedThroughTime() {
        if (!TextUtils.isEmpty(ThroughTime)) {
            try {
                Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm").parse(ThroughTime);


                if (DateUtils.isToday(date)) {
                    return new SimpleDateFormat("HH:mm").format(date);
                } else if (DateUtils.isYesterday(date)) {
                    return "昨天 " + new SimpleDateFormat("HH:mm").format(date);
                } else if (DateUtils.isThisYear(date)) {
                    return new SimpleDateFormat("MM/dd HH:mm").format(date);
                } else {
                    return ThroughTime;
                }

            } catch (ParseException e) {
                e.printStackTrace();
                return ThroughTime;
            }
        }
        return "";
    }

    @Override
    public String toString() {
        return "LevelDetail{" +
                "Id=" + Id +
                ", LevelId=" + LevelId +
                ", Title='" + Title + '\'' +
                ", QuestionCount=" + QuestionCount +
                ", Description='" + Description + '\'' +
                ", LevelType=" + LevelType +
                ", CorrectRate=" + CorrectRate +
                ", ThroughTime='" + ThroughTime + '\'' +
                ", ClearanceTime=" + ClearanceTime +
                ", CompletionStatus=" + CompletionStatus +
                ", LockStatus=" + LockStatus +
                ", PreLevel=" + PreLevel +
                ", PreScene=" + PreScene +
                ", QuestionList=" + QuestionList +
                ", BestRank=" + BestRank +
                ", CompleteType=" + CompleteType +
                '}';
    }
}
